package jmx;

import javax.management.AttributeChangeNotification;
import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by sunyuming on 19/1/25.
 */
public class Hello extends NotificationBroadcasterSupport implements HelloMXBean {

    private AtomicLong sequenceNumber = new AtomicLong(1);

    private String name = "tes";
    private MyType myType = new MyType();
    private Integer i = 1;

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {

        AttributeChangeNotification notification = new AttributeChangeNotification(this,
                sequenceNumber.getAndIncrement(), System.currentTimeMillis(),
                AttributeChangeNotification.ATTRIBUTE_CHANGE, "Server Host Change", "java.lang.String", this.name,
                this.name);


        super.sendNotification(notification);
        super.sendNotification(new Notification("jack.hi",this, sequenceNumber.getAndIncrement(),System.currentTimeMillis(),"jack"));

        this.name = name;
    }

    @Override
    public String printHello() {
        return "Hello "+ name;
    }

    @Override
    public String printHello(String whoName) {
        return "Hello  " + whoName;
    }

    @Override
    public MyType getMyType() {
        return myType;
    }

    @Override
    public void setMyType(MyType myType) {
        this.myType = myType;
    }

    // @Override
    public Integer getI() {
        return i;
    }

    //@Override
    public void setI(Integer i) {
        this.i = i;
    }
}